﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunny.Controls
{
	public class BooleanSelector : Sunny.Controls.DropDownList
	{
		private System.Collections.Generic.Dictionary<bool, string> _DataSource;
		protected System.Collections.Generic.Dictionary<bool, string> DataSource
		{
			get
			{
				if (this._DataSource == null)
				{
					this._DataSource = new Dictionary<bool, string>();
					this._DataSource.Add(true, "是");
					this._DataSource.Add(false, "否");
				}
				return this._DataSource;
			}
		}

		public string TrueText
		{
			get
			{
				return this.DataSource[true];
			}
			set
			{
				this.DataSource[true] = value;
			}
		}

		public string FalseText
		{
			get
			{
				return this.DataSource[false];
			}
			set
			{
				this.DataSource[false] = value;
			}
		}

		//public void SetText(bool key, string value)
		//{
		//    this.DataSource[key] = value;
		//}

		public BooleanSelector()
		{
			this.DisplayMemberPath = "Value";
			this.SelectedValuePath = "Key";
			this.ItemsSource = this.DataSource;

			this.Width = 40;
		}

		public bool? SelectedBoolean
		{
			get
			{
				if (this.SelectedValue is Telerik.Windows.Controls.RadComboBoxItem)
					return null;
				return (bool?)(this.SelectedValue);
			}
			set
			{
				this.SelectedValue = value.ToString();
			}
		}

		public override string ValueProperty
		{
			get
			{
				return "SelectedBoolean";
			}
		}

		//public override object Value
		//{
		//    get
		//    {
		//        return this.SelectedBoolean;
		//    }
		//}
	}
}